package com.zjw.zy.heart.service.http.factory;



import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import com.zjw.zy.heart.bean.weather.WeatherDaysResult;
import com.zjw.zy.heart.bean.weather.WeatherHoursResult;
import com.zjw.zy.heart.service.http.convert.DayWeatherConverter;
import com.zjw.zy.heart.service.http.convert.HourlyWeatherConverter;
import lombok.NonNull;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/9/27 16:10
 */
public class ConvertFactory extends Converter.Factory {

    private final DayWeatherConverter dayWeatherConverter = new DayWeatherConverter();
    private final HourlyWeatherConverter hourlyWeatherConverter = new HourlyWeatherConverter();

    @Override
    public Converter<ResponseBody, ?> responseBodyConverter(@NonNull Type type, @NonNull Annotation[] annotations, @NonNull Retrofit retrofit) {
        if (WeatherDaysResult.class.equals(type)) {
            return dayWeatherConverter;
        }
        if (WeatherHoursResult.class.equals(type)) {
            return hourlyWeatherConverter;
        }
        return super.responseBodyConverter(type, annotations, retrofit);
    }
}
